<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="标题">
              <a-input
                placeholder="请输入标题"
                v-model="queryParam.title"
              ></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="接收人">
              <a-select
                showSearch
                v-model="queryParam.receiverid"
                placeholder="请选择接收人(可搜索)"
                @search="searchChange($event)"
                option-filter-prop="children"
                :filter-option="filterOption"
              >
                <a-select-option
                  :value="item.id"
                  v-for="(item, index) in list"
                  :key="index"
                  >{{ item.realname }}</a-select-option
                >
              </a-select>
            </a-form-item>
          </a-col>

          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="创建时间">
                <a-date-picker
                  valueFormat="YYYY-MM-DD"
                  v-model="queryParam.dateTime"
                  style="width: 100%"
                />
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span
              style="float: left;overflow: hidden;"
              class="table-page-search-submitButtons"
            >
              <a-button type="primary" @click="searchQuery" icon="search"
                >查询</a-button
              >
              <a-button
                type="primary"
                @click="searchReset"
                icon="reload"
                style="margin-left: 8px"
                >重置</a-button
              >
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? "收起" : "展开" }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary">发布通知</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :rowSelection="{
          selectedRowKeys: selectedRowKeys,
          onChange: onSelectChange,
        }"
        @change="handleTableChange"
      >
        <span slot="pushMethod" slot-scope="text">
          {{ text == 1 ? "手动" : "自动" }}
        </span>
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-popconfirm
                  title="确定删除吗?"
                  @confirm="() => handleDelete(record.id)"
                >
                  <a>删除</a>
                </a-popconfirm>
          <!-- <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm
                  title="确定删除吗?"
                  @confirm="() => handleDelete(record.id)"
                >
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown> -->
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <messageNotice-modal
      ref="modalForm"
      @ok="modalFormOk"
    ></messageNotice-modal>
  </a-card>
</template>

<script>
import "@/assets/less/TableExpand.less";
import MessageNoticeModal from "./modules/MessageNoticeModal";
import { JeecgListMixin } from "@/mixins/JeecgListMixin";
import { sysUserList } from "@/api/tsapi";
export default {
  name: "AssetDetailList",
  mixins: [JeecgListMixin],
  components: {
    MessageNoticeModal,
  },
  data() {
    return {
      description: "资产管理明细管理页面",
      // 表头
      columns: [
        {
          title: "接收人",
          align: "center",
          dataIndex: "receiverName",
        },
        {
          title: "推送方式",
          align: "center",
          dataIndex: "pushMethod",
          scopedSlots: { customRender: "pushMethod" },
        },
        {
          title: "标题",
          align: "center",
          dataIndex: "title",
        },
        {
          title: "内容",
          align: "center",
          dataIndex: "content",
        },
        {
          title: "创建时间",
          align: "center",
          dataIndex: "createTime",
        },
        {
          title: "操作",
          dataIndex: "action",
          align: "center",
          scopedSlots: { customRender: "action" },
        },
      ],
      url: {
        list: `/MessageNotice/messageNotice/list`,
        delete: "/MessageNotice/messageNotice/delete",
        deleteBatch: "/MessageNotice/messageNotice/deleteBatch",
        exportXlsUrl: "MessageNotice/messageNotice/exportXls",
        importExcelUrl: "MessageNotice/messageNotice/importExcel",
      },
      list: [],
    };
  },
  mounted() {
    this.userlist();
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG["domianURL"]}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    userlist(e) {
      let params = {
        realname: e,
      };
      sysUserList(params).then((res) => {
        if (res.code == 200) {
          this.list = res.result.records;
        }
      });
    },
    searchChange(e) {
      this.userlist(e);
    },
    filterOption(input, option) {
      return (
        option.componentOptions.children[0].text
          .toLowerCase()
          .indexOf(input.toLowerCase()) >= 0
      );
    },
  },
};
</script>
<style scoped>
@import "~@assets/less/common.less";
</style>
